package com.b511.swpu.cementbackend.controller;

import com.b511.swpu.cementbackend.dto.input.MetaDictInputDto;
import com.b511.swpu.cementbackend.dto.input.NavigationInputDto;
import com.b511.swpu.cementbackend.dto.input.RegisterInputDto;
import com.b511.swpu.cementbackend.entity.MAIN_Person;
import com.b511.swpu.cementbackend.entity.SysRole;
import com.b511.swpu.cementbackend.service.SysManageService;
import com.b511.swpu.cementbackend.util.R;
import io.swagger.annotations.Api;
import org.springframework.data.domain.PageRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(value = "系统管理", tags = {"系统管理"})
@RestController
@RequestMapping("/sysmanage")
public class SysManageController {
    private final SysManageService sysManageService;

    public SysManageController(SysManageService sysManageService) {
        this.sysManageService = sysManageService;
    }



    @GetMapping("/datadict")
    public R getDataDictTree() {
        return sysManageService.getDataDictTree();
    }

    @GetMapping("/companystructure")
    public R getCompanyStructureTree() {
        return sysManageService.getCompanyStructureTree();
    }

    @GetMapping("/employeemanage/{num}/{size}")
    public R getEmployeeManage(@PathVariable int num,@PathVariable int size) throws Exception {
        return sysManageService.getEmployeeManage(num,size);
    }

    @GetMapping("/datadict/{code}")//国家下面的油田，油田下的区块
    public R getOneDataDict(@PathVariable String code) {
        return sysManageService.getOneDataDict(code);
    }

    @GetMapping("/datadict_name")//根据name查数据字典
    public R getDataDictByName(@ModelAttribute @Validated MetaDictInputDto metaDictInputDto) {
        return sysManageService.getDataDictByName(metaDictInputDto.getLabel());
    }

    //返回数据字典中的区域
    @GetMapping("/area")
    public R getArea(){
        return sysManageService.getArea();
    }

    //返回数据字典中的井型
    @GetMapping("/WellType")
    public R getWellType(){
        return sysManageService.getWellType();
    }

    //返回数据字典中的井型
    @GetMapping("/CaseSize")
    public R getCaseSize(){
        return sysManageService.getCaseSize();
    }

    //返回数据字典中的井别
    @GetMapping("/WellSpacing")
    public R getWellSpacing(){
        return sysManageService.getWellSpacing();
    }

    //通过公司名称、部门名称和姓名来查询人员信息
    @GetMapping("/queryByName")
    public R execUpdate(@RequestParam(value = "companyname",required = false)  String companyname,@RequestParam(value = "departmentname",required = false)  String departmentname,@RequestParam(value = "name",required = false) String name,@RequestParam(value = "num",required = false)  Integer num, @RequestParam(value = "size",required = false) Integer size) {
        return sysManageService.queryByName(companyname,departmentname,name,num,size);
    }

    //返回公司树状json
    @GetMapping("/queryCompanyTree")
    public R queryCompanyTree() {
        return sysManageService.queryCompanyTree();
    }

    //注册用户
    @PostMapping("/register")
    public R register(@RequestBody RegisterInputDto registerInputDto) {
        return sysManageService.register(registerInputDto);
    }

    //注销用户账号
    @GetMapping("/logout")
    public R logout(@RequestParam(value = "code",required = false)  String code) throws Exception {
        return sysManageService.logout(code);
    }

    @GetMapping("/querySysRole")
    public R querySysRole(){
        return sysManageService.querySysRole();
    }

    @GetMapping("/queryCompanyName")
    public R queryCompanyName() {
        return sysManageService.queryCompanyName();
    }

    @GetMapping("/queryDepartmentName")
    public R querydepartmentName() {
        return sysManageService.querydepartmentName();
    }

    @PostMapping("/createMainPerson")
    public R createMainPerson(@RequestBody MAIN_Person main_person) {
        return sysManageService.createMainPerson(main_person);
    }

    @GetMapping("/queryMainPerson")
    public R queryMainPerson(@RequestParam(value = "code",required = false)  String code) {
        return sysManageService.queryMainPerson(code);
    }

    @PostMapping("/updateMainPerson")
    public R updateMainPerson(@RequestBody MAIN_Person main_person) {
        return sysManageService.updateMainPerson(main_person);
    }

    @DeleteMapping("/deleteMainPerson")
    public R deleteMainPerson(@RequestParam(value = "code",required = false)  String code) {
        return sysManageService.deleteMainPerson(code);
    }

    //返回所有前端导航栏所有权限
    @GetMapping("/queryAllNavigation")
    public R queryAllNavigation() {
        return sysManageService.queryAllNavigation();
    }

    //根据sysrole(比如：系统管理员)来查询导航栏权限,返回结果是树
    @GetMapping("/queryNavigationBysysrole")
    public R queryNavigationBysysrole(@RequestParam(value = "sysrole",required = false)  String sysrole) {
        return sysManageService.queryNavigationBysysrole(sysrole);
    }

    //根据sysrole(比如：系统管理员)来查询导航栏权限,返回结果是list
    @GetMapping("/queryNavigationByRole")
    public R queryNavigationByRole(@RequestParam(value = "sysrole",required = false)  String sysrole) {
        return sysManageService.queryNavigationByRole(sysrole);
    }

    //更新导航栏权限
    @PostMapping("/updateNavigationByRole")
    public R updateNavigationByRole(@RequestBody NavigationInputDto navigationInputDto) {
        return sysManageService.updateNavigationByRole(navigationInputDto);
    }

    //查询所有角色（sys_role）信息
    @GetMapping("/queryAllRole")
    public R queryAllRole(@RequestParam(value = "num",required = false)  Integer num, @RequestParam(value = "size",required = false) Integer size){
        return sysManageService.queryAllRole(num,size);
    }

    //新增角色（sys_role）信息
    @PostMapping("/createNewRole")
    public R createNewRole(@RequestBody SysRole sysRole){
        return sysManageService.createNewRole(sysRole);
    }

    //更新角色（sys_role）信息
    @PostMapping("/updateRole")
    public R updateRole(@RequestBody SysRole sysRole){
        return sysManageService.updateRole(sysRole.getName(),sysRole.getId());
    }

    //删除角色（sys_role）信息
    @DeleteMapping("/deleteRole")
    public R deleteRole(@RequestParam(value = "id",required = false)  String id){
        return sysManageService.deleteRole(id);
    }

    //模糊查询角色信息
    @GetMapping("/queryAllRoleLikeName")
    public R queryAllRoleLikeName(@RequestParam(value = "name",required = false)  String name,@RequestParam(value = "num",required = false)  Integer num, @RequestParam(value = "size",required = false) Integer size){
        return sysManageService.queryAllRoleLikeName(name,num,size);
    }

    //根据id查询某个角色（sys_role）信息
    @GetMapping("/queryRoleByID")
    public R queryRoleByID(@RequestParam(value = "id",required = false)  String id){
        return sysManageService.queryRoleByID(id);
    }
}
